
#include "SimpleIo.h"


void  writeUint8(FILE *f,unsigned char c)
{
  fputc(c,f);
}

void writeUint16(FILE *f,unsigned short s)
{
  fputc(s>>8,f);
  fputc(s&0xff,f);
}

void writeUint32(FILE *f,unsigned int s)
{
  fputc((s>>24)&0xff,f);
  fputc((s>>16)&0xff,f);
  fputc((s>>8)&0xff,f);
  fputc(s&0xff,f);
}

unsigned char readUint8(FILE *f)
{
  unsigned char c;
  c=fgetc(f);
  return  c;
}

unsigned short readUint16(FILE *f)
{
  unsigned char a,b;
  a=readUint8(f);
  b=readUint8(f);

  return ((unsigned short)a<<8)|b;
}

void readUint16Array(unsigned short  howMany,unsigned short * buffer,FILE *f )
{
  for(int i;i<howMany;i++) {
    buffer[i]=readUint16(f);
  }
}

unsigned int readUint32(FILE *f)
{
  unsigned char a,b,c,d;
  a=readUint8(f);
  b=readUint8(f);
  c=readUint8(f);
  d=readUint8(f);

  return ((unsigned int)a<<24)|
         ((unsigned int)b<<16)|
         ((unsigned int)c<<8)|
         ((unsigned int)d);
}

